const express = require("express");
const route = express.Router();

var mysql = require("mysql");

var pool = mysql.createPool({
  connectionLimit: 10,
  host: "localhost",
  user: "root",
  password: "mWXS19971222@.",
  database: "bookstore",
});

route.get("/getBooks", (req, res) => {
  console.log("getBooks", req.query);
  // let sql = "select * from book where bookname like '%Java%'";
  let sql = "select * from book";
  pool.getConnection(function (err, connection) {
    if (err) throw err;
    connection.query(sql, function (error, results, fields) {
      connection.release();

      console.log(results);
      res.render("book", {
        res: results,
      });

      if (error) throw error;
    });
  });
});

module.exports = route;
